﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace GameStateManagement
{
    public class Checkpoint : OrbitingActor
    {
        float m_fMagnitudeRatio;

        public Checkpoint(Game game, float magnitudeRatio, float speed)
            :base(game)
        {
            sMeshName = "Checkpoint";
            m_fScale = 1.0f;
            
            // Physics
            fMass = 1.0f;
            fTerminalVelocity = 100.0f;
            vAcceleration = Vector3.Zero;
            bPhysicsDriven = true;

            m_fSpeed = speed;
            m_fMagnitudeRatio = magnitudeRatio;

            m_qRotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.PiOver2);
        }

        public override void Update(GameTime gameTime)
        {
            if (!GameplayScreen.pause && !GameplayScreen.gameOver)
            {
                // Scale the radius to the shrinking sphere.
                ScaleRadiusBetweenSphereAndPlanet(m_fMagnitudeRatio);

                // Rotate checkpoint.
                m_qRotation *= Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)Math.PI * 0.5f * (float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            base.Update(gameTime);
        }

        public void ShipCollide()
        {
            // Pass to the checkpoint manager.
            CheckpointManager.GetCheckpointManager().CheckpointPassed(this);
        }

        /// <summary>
        /// Remove this checkpoint from the game.
        /// </summary>
        public void Kill()
        {
            Game.Components.Remove(this);
        }
    }
}
